//
//   UIImage+Extension.swift
//  weibo1
//
//  Created by changhongliang on 2017/8/22.
//  Copyright © 2017年 richinfo. All rights reserved.
//

import UIKit

extension UIImage {
    class func resizeImage(image:UIImage,centerInSize:CGSize) -> UIImage? {
        let size = image.size
        let scale = max(centerInSize.width/size.width, centerInSize.height/size.height)
         UIGraphicsBeginImageContext(centerInSize)
        let width = size.width * scale
        let height = size.height * scale
        let dwidth = (centerInSize.width - width) / 2.0
        let dheight = (centerInSize.height - height) / 2.0
        let rect = CGRect(x: dwidth, y: dheight, width: size.width * scale  , height: size.height * scale )
        image.draw(in: rect)
        let newImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return newImage
    }

}
